<?php
	require_once 'classes/DBMysql.php';
	function getAllImages() {
		$dbConnection = DBMysql::Instance();
		$query = "Select * from images;";
		$statement = $dbConnection->execute($query);
		return $statement;
	}
	
	if(isset($_GET['format'])) {
		if ($_GET['format'] == "json") {
			$statement = getAllImages();
			echo json_encode($statement->fetchall_assoc(), JSON_PRETTY_PRINT);
		}
		elseif($_GET['format'] == "xml") {
			$statement = getAllImages();
			$imgArr = $statement->fetchall_assoc();
			echo "&ltimages&gt<br />";
			foreach($imgArr as $arr) {
				echo "&ltimage&gt<br />";
				foreach($arr as $key => $value) {
					echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt$key&gt$value&lt/$key&gt<br />";
				}
				echo "&lt/image&gt<br />";
			}
			echo "&lt/images&gt";
		}
		else {
			echo "Undefined Format: Choose between json and xml";
		}
	}
?>